package com.lemon.smartsafetynew.ui.adapter.electrical;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lemon.smartsafety.R;
import com.lemon.smartsafety.listener.RecyclerTClickListener;
import com.lemon.smartsafetynew.entity.electrical.ElectricalCompanyVo;
import com.lemon.smartsafetynew.util.common.CommonUtil;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import kale.adapter.LemonRcvAdapter;
import kale.adapter.item.AdapterItem;

/**
 * Created by Andrew on 2018/3/13.
 */

public class ElectricalCompanyAdapter extends LemonRcvAdapter<ElectricalCompanyVo> {

    private RecyclerTClickListener<ElectricalCompanyVo> mListener;

    public ElectricalCompanyAdapter(@Nullable List<ElectricalCompanyVo> data,
                                    RecyclerTClickListener<ElectricalCompanyVo> mListener) {
        super(data);
        this.mListener = mListener;
    }

    @NonNull
    @Override
    public AdapterItem createItem(Object type) {
        return new CompanyItem();
    }

    public class CompanyItem implements AdapterItem<ElectricalCompanyVo> {

        private ElectricalCompanyVo data;
        private int pos;

        @Bind(R.id.monitor_item_tv)
        TextView monitorItemTv;
        @Bind(R.id.company_name_tv)
        TextView companyNameTv;
        @Bind(R.id.company_safer_tv)
        TextView companySaferTv;
        @Bind(R.id.safer_tel_tv)
        TextView saferTelTv;
        @Bind(R.id.item_layout)
        LinearLayout itemLayout;

        @Override
        public int getLayoutResId() {
            return R.layout.item_electrical_company_recycler_item;
        }

        @Override
        public void bindViews(View root) {
            ButterKnife.bind(this, root);
        }

        @Override
        public void setViews() {
            itemLayout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mListener.onItemClick(data, pos);
                }
            });
        }

        @Override
        public void handleData(ElectricalCompanyVo electricalCompanyVo, int position) {

            data = electricalCompanyVo;
            pos = position;

            monitorItemTv.setText(CommonUtil.avoidNullString(electricalCompanyVo.getAddress()));
            if (!TextUtils.isEmpty(electricalCompanyVo.getCompanyName())) {
                electricalCompanyVo.setProjectName(electricalCompanyVo.getCompanyName());
            }
            companyNameTv.setText(CommonUtil.avoidNullString(electricalCompanyVo.getProjectName()));
            if (!TextUtils.isEmpty(electricalCompanyVo.getAqy1Name())) {
                electricalCompanyVo.setDutyPerson(electricalCompanyVo.getAqy1Name());
            }
            companySaferTv.setText(CommonUtil.avoidNullString(electricalCompanyVo.getDutyPerson()));
            if (!TextUtils.isEmpty(electricalCompanyVo.getAqy1Phone())) {
                electricalCompanyVo.setTelPhone(electricalCompanyVo.getAqy1Phone());
            }
            saferTelTv.setText(CommonUtil.avoidNullString(electricalCompanyVo.getTelPhone()));

        }
    }
}
